package main

import (
	"context"
	"log"

	testutils "github.com/smallnest/rpcx/_testutils"
	"github.com/smallnest/rpcx/client"
)

func main() {

	// #1
	d, err := client.NewPeer2PeerDiscovery("tcp@127.0.0.1:8972", "")
	// #2
	xclient := client.NewXClient("Arith", client.Failtry, client.RandomSelect, d, client.DefaultOption)
	defer xclient.Close()

	args := testutils.ThriftArgs_{}

	// #3
	args.A = 200
	args.B = 100

	// #4
	reply := testutils.ThriftReply{}

	// #5
	err = xclient.Call(context.Background(), "Mul", &args, &reply)
	if err != nil {
		log.Fatalf("failed to call: %v", err)
	}

	log.Printf("%d * %d = %d", args.A, args.B, reply.C)
}
